<%# This is used to display basic git setup instructions, like on github... %>
<% flash.now[:warning] = l(:notice_empty_repository) %>

<div class="box">
  <% if User.current.allowed_to?(:view_changesets, @project) %>
    <h2><%= l(:label_help_git_setup) %> :</h2>

    <pre>
      <a href="http://git-scm.com/download" target="_blank"><%= l(:label_download_and_install_git) %></a>
      git config --global user.name "<%= User.current.name(:firstname_lastname) %>"
      git config --global user.email <%= User.current.mail ? User.current.mail : "mail@example.com" %>
      <% if !User.current.anonymous? && User.current.gitolite_public_keys.active.length == 0 %>
      <%= link_to "Upload SSH Public Key", {:controller => 'my', :action => 'account'} %>
      <% end %>
    </pre>

    <% if User.current.allowed_to?(:commit_access, @project) %>
    <div id="repository_setup">
    <h2><%= l(:label_help_repository_setup_new) %> :</h2>
    <pre>
      mkdir <%= @repository.redmine_name %>
      cd <%= @repository.redmine_name %>
      git init
      touch readme.txt
      git add readme.txt
      git commit -m 'Initializing <%= @repository.redmine_name %> repository'
      git remote add origin <span class="git_url_access"></span>
      git push -u origin master
    </pre>

    <h2><%= l(:label_help_repository_setup_existing) %> :</h2>
    <pre>
      cd existing_git_repo
      git remote add origin <span class="git_url_access"></span>
      git push -u origin master
    </pre>
    </div>
    <% end %>

    <h2><%= l(:label_help_repository_clone) %> :</h2>
    <pre>
      git clone <span class="git_url_access"></span>
    </pre>
  <% else %>
    <%= l(:label_help_no_repo_rights) %>
  <% end %>
</div>

<% content_for :sidebar do %>
  <h3><%= l(:label_repository_plural) %></h3>
  <ul class="repository git">
    <% @repositories.sort.each do |repo| %>
        <li class="repository git"><%= link_to h(repo.name), {:controller => 'archived_repositories', :action => 'show', :id => @project, :repository_id => repo.identifier_param, :rev => nil, :path => nil},
                                      :class => 'repository' + (@repository.is_a?(Repository::Xitolite) ? ' git' : '') + (repo == @repository ? ' selected' : '') %>
        </li>
    <% end %>
  </ul>

  <% if @repository.is_a?(Repository::Xitolite) && @repository.urls_are_viewable? %>
    <div class="git_hosting_urls">
      <h3><%= l(:label_repository_access_url) %></h3>
      <%= render :partial => 'common/git_urls', :locals => {:repository => @repository} %>
    </div>
  <% end %>
<% end %>

<% content_for :header_tags do %>
  <%= javascript_tag do %>
    $(document).ready(function() {
      var key = $('#git_url_list li').first().attr('id');
      var access = access_list[key];

      $('.git_url_access').html(access.url);

      $('#git_url_list li').on('click', function(){
        var key  = $(this).attr('id');
        var access = access_list[key];

        $('.git_url_access').html(access.url);

        if (access.commiter == true) {
          $('#repository_setup').show();
        } else {
          $('#repository_setup').hide();
        }
      });
    });
  <% end %>
<% end %>
